package com.youkeda.app.dataobject;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

import com.youkeda.app.model.RedEnvelope;
import com.youkeda.app.util.UUIDUtils;
import lombok.Data;
import org.springframework.util.StringUtils;

/**
 * 父红包
 * @author 
 */
@Data
public class RedEnvelopeDO implements Serializable {
    private String id;

    private String sendUserId;

    private BigDecimal redEnvelopeAmount;

    private Integer totalAmount;

    private String note;

    private Date gmtCreated;

    private Date gmtModified;

    private static final long serialVersionUID = 1L;

    public RedEnvelopeDO(RedEnvelope redEnvelope) {
        if (StringUtils.isEmpty(redEnvelope.getId())) {
            this.setId(UUIDUtils.getUUID());
        }
        this.setNote(redEnvelope.getNote());
        this.setRedEnvelopeAmount(new BigDecimal(redEnvelope.getRedEnvelopeAmount()));
        this.setSendUserId(redEnvelope.getSendUserId());
        this.setTotalAmount(redEnvelope.getTotalAmount());
    }

    public RedEnvelope convertToModel() {
        RedEnvelope redEnvelope = new RedEnvelope();
        redEnvelope.setId(this.getId());
        redEnvelope.setNote(this.getNote());
        if (this.getRedEnvelopeAmount() != null) {
            redEnvelope.setRedEnvelopeAmount(this.getRedEnvelopeAmount().doubleValue());
        }
        redEnvelope.setSendUserId(this.getSendUserId());
        redEnvelope.setTotalAmount(this.getTotalAmount());
        Date date = this.getGmtCreated();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        redEnvelope.setGmtCreated(localDateTime);
        Date date1 = this.getGmtModified();
        Instant instant1 = date1.toInstant();
        ZoneId zoneId1 = ZoneId.systemDefault();
        LocalDateTime localDateTime2 = instant1.atZone(zoneId1).toLocalDateTime();
        redEnvelope.setGmtModified(localDateTime2);
        return redEnvelope;
    }
}